package com.ly.algorithm.offerpointer;



import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;

/**
 * @Classname Offer06
 * @Description
 *
 * 输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
 *
 *
 *
 * 示例 1：
 *
 * 输入：head = [1,3,2]
 * 输出：[2,3,1]
 *
 * @Date 2020/12/30 19:58
 * @Author 冷心影翼
 */
public class Offer06 {

    public static void main(String[] args) {
        Solution06 solution06 = new Solution06();
        ListNode init = ListNode.init(new int[]{1, 3, 2});
        System.out.println(solution06.reversePrint(init));
    }
}


class Solution06 {
    public int[] reversePrint(ListNode head) {

        ListNode cur = head;
        int size = 0;
        while (cur!=null) {
            cur = cur.next;
            size++;
        }

        int[] arr = new int[size];
        cur = head;
        size--;
        while (cur!=null) {
            arr[size--] = cur.val;
            cur = cur.next;

        }
        return arr;
    }
}